package com.nd.te.province;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class bean implements WritableComparable<bean> {

    private int iyear;
    private String country;
    private String province;

    public int getIyear(){
        return this.iyear;
    }

    public String getCountry(){
        return this.country;
    }

    public String getProvince(){
        return province;
    }

    public void set(int iyear, String country, String province){
        this.iyear=iyear;
        this.country=country;
        this.province=province;
    }

    @Override
    public int compareTo(bean o) {
        if (this.getIyear() > o.getIyear()){
            return 1;
        }else if(this.getIyear() < o.getIyear()){
            return -1;
        }

        int i = 0;
        if (o instanceof bean) {
            bean cc = (bean) o;
            i = this.country.compareTo(cc.country);
            if (i == 0) {
                return this.province.compareTo(cc.province);
            }
        }
        return i;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(iyear);
        dataOutput.writeUTF(country);
        dataOutput.writeUTF(province);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        iyear=dataInput.readInt();
        country=dataInput.readUTF();
        province=dataInput.readUTF();
    }

    public String toString(){
        return iyear
                +","+country
                +","+province;
    }
}
